﻿<%@ WebHandler Language="C#" Class="DemoAutoComplate" %>
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Text;
public class DemoAutoComplate : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        string prefixText = context.Request.QueryString["q"];
        string ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
        using (SqlConnection conn = new SqlConnection())
        {
            conn.ConnectionString = ConnectionString; 
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = "select FullName from tb_Applicant where FullName like @SearchText + '%'";
                cmd.Parameters.AddWithValue("@SearchText", prefixText);
                cmd.Connection = conn;
                StringBuilder sb = new StringBuilder();
                conn.Open();
                using (SqlDataReader sdr = cmd.ExecuteReader())
                {
                    while (sdr.Read())
                    {
                        sb.Append(sdr["FullName"])
                            .Append(Environment.NewLine);
                    }
                }
                conn.Close();
                context.Response.Write(sb.ToString());
            }
        }
    }
    public bool IsReusable {
        get {
            return false;
        }
    }
}